import com.google.gson.FieldNamingStrategy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.lang.reflect.Field;

public class GsonSample {
    public static void main(String[] args) {
        Diaosi wu = new Diaosi();

        wu.setName("吴海松");
        wu.setAge(23.5);
        wu.setBirthday("1997-12-19");
        wu.setSchool("哈尔滨信息工程学院");
        wu.setMajor( new String[]{"理发","挖掘机"});
        wu.setHas_girlfriend(false);
        wu.setCar(null);
        wu.setHouse(null);
        wu.setComment("这是一个注释");
        wu.setIgnore("不要看见我");

        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.setPrettyPrinting();//设置漂亮的印刷
        //设置字段命名策略
        gsonBuilder.setFieldNamingStrategy(new FieldNamingStrategy() {
            @Override
            public String translateName(Field field) {

                if (field.getName().equals("name")) {
                    return "NAME";
                }

                return field.getName();
            }
        });

        Gson gson = gsonBuilder.create();
        String s = gson.toJson(wu);
        System.out.println(s);

    }
}
